package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Product_list;
import com.ruoyi.system.service.IProduct_listService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品列表Controller
 * 
 * @author rss
 * @date 2023-09-03
 */
@Controller
@RequestMapping("/system/list")
public class Product_listController extends BaseController
{
    private String prefix = "system/list";

    @Autowired
    private IProduct_listService product_listService;

    @RequiresPermissions("system:list:view")
    @GetMapping()
    public String list()
    {
        return prefix + "/list";
    }

    /**
     * 查询产品列表列表
     */
    @RequiresPermissions("system:list:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Product_list product_list)
    {
        startPage();
        List<Product_list> list = product_listService.selectProduct_listList(product_list);
        return getDataTable(list);
    }

    /**
     * 导出产品列表列表
     */
    @RequiresPermissions("system:list:export")
    @Log(title = "产品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Product_list product_list)
    {
        List<Product_list> list = product_listService.selectProduct_listList(product_list);
        ExcelUtil<Product_list> util = new ExcelUtil<Product_list>(Product_list.class);
        return util.exportExcel(list, "产品列表数据");
    }

    /**
     * 新增产品列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品列表
     */
    @RequiresPermissions("system:list:add")
    @Log(title = "产品列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Product_list product_list)
    {
        return toAjax(product_listService.insertProduct_list(product_list));
    }

    /**
     * 修改产品列表
     */
    @RequiresPermissions("system:list:edit")
    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId") Long productId, ModelMap mmap)
    {
        Product_list product_list = product_listService.selectProduct_listByProductId(productId);
        mmap.put("product_list", product_list);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品列表
     */
    @RequiresPermissions("system:list:edit")
    @Log(title = "产品列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Product_list product_list)
    {
        return toAjax(product_listService.updateProduct_list(product_list));
    }

    /**
     * 删除产品列表
     */
    @RequiresPermissions("system:list:remove")
    @Log(title = "产品列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(product_listService.deleteProduct_listByProductIds(ids));
    }
}
